#!/bin/sh

if [ "x$1" == "x" ]; then
  echo "Error: content cannot be null";
  echo "Usage: sh sina.sh content"
  exit 1;
fi
username="youraccount@sina.com"
password="yourpassword"
cookie_file="sina.cookie"
#curl -k -c $cookie_file "https://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.3.11)&service=sso&client=ssologin.js%28v1.3.11%29&entry=sso&encoding=GB2312&gateway=1&savestate=0&from=&useticket=0&username=yangyou0332@sina.com&password=589345123&callback=parent.sinaSSOController.loginCallBack&returntype=IFRAME&setdomain=1"
uid_n=`curl -k -c $cookie_file "https://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.3.11)&service=sso&client=ssologin.js%28v1.3.11%29&entry=sso&encoding=GB2312&gateway=1&savestate=0&from=&useticket=0&username=$username&password=$password&callback=parent.sinaSSOController.loginCallBack&returntype=TEXT&setdomain=1" 2>/dev/null |grep -c "uid"`
if [ $uid_n -eq 0 ]; then
    echo "登录失败!"
    exit 1;
fi
res=`curl -e "http://t.sina.com.cn/" -b $cookie_file -d "content=$1" "http://t.sina.com.cn/mblog/publish.php" 2>/dev/null|grep -c 'A00006' `
if [ $res -eq 1 ]; then
   echo -e "\033[1;32m发表成功!\033[0m"

else
   echo -e "\033[1;31m发表失败!\033[0m"
fi
